﻿// -----------------------------------------------------------------------
// <copyright file="ConexionBD.cs" company="HP">
// TODO: Update copyright text.
// </copyright>
// -----------------------------------------------------------------------

using System.Configuration;
using System.Data;
using System.Data.Common;
using System.Data.SqlClient;
using System.Windows.Forms;

namespace Bostik
{
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;

    /// <summary>
    /// TODO: Update summary.
    /// </summary>
    public class ConexionBD
    {

        private SqlConnection conexion = null;
        private ConnectionStringSettings cadena = null; 
        private DbConnection conexionDB = null;
        private DbCommand comando = null;
        private DbTransaction transaccion = null;
        private string cadenaConexion;
        private static DbProviderFactory factory = null;


        public void ConectarToDB()
        {
            try
            {
                cadena = ConfigurationManager.ConnectionStrings["BDBostik"];

                using (conexion = new SqlConnection())
                {
                    conexion.ConnectionString = cadena.ConnectionString;
                    conexion.Open();

                    if (conexion.State == ConnectionState.Open)
                    {
                        var CadenaBD = "Base de datos: " + conexion.Database  +
                       "Origen de datos: {0}"+ conexion.DataSource+
                        "Servidor: {0}" +conexion.WorkstationId+
                       "Version: {0}" +conexion.ServerVersion +
                         "\nCadena Conexion: {0}"+ conexion.ConnectionString;
                        MessageBox.Show(CadenaBD, "Bostik", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                }
            }
            catch (SqlException ex)
            {                                     
                MessageBox.Show(ex.Message, "Bostik", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            finally
            {
                if (conexion.State == ConnectionState.Closed)
                {
                    MessageBox.Show("Conexion Cerrada", "Bostik", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
        }

        public void BaseDatos() 
        {
        
        }

    }
}
